<template>
  <!-- 吸顶组件 -->
  <div class="app-head-sticky" :class="{show: y>= 78}">
    <div class="container" v-show="y>=78">
      <router-link to="/" class="logo"></router-link>
      <AppHeadNav />
      <div class="right-link">
        <router-link to="/">品牌</router-link>
        <router-link to="/">专题</router-link>
      </div>
    </div>
  </div>
</template>

<script>
import { ref, onMounted } from 'vue'
import AppHeadNav from './children/app-head-nav.vue'
export default {
  name: 'AppHeadSticky',
  components: {
    AppHeadNav
  },
  setup () {
    const y = ref(0)
    // DOM渲染完成之后 添加滚动事件，滚动到一定位置后显示吸顶部分
    onMounted(() => {
      window.onscroll = () => {
        const TopScroll = document.documentElement.scrollTop
        y.value = TopScroll
      }
    })
    return { y }
  }
}
</script>

<style lang="less" scoped>
.app-head-sticky {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  height: 80px;
  width: 100%;
  background-color: #fff;
  transform: translateY(-100%);
  opacity: 0;
  z-index: 9999;
  &.show {
    transform: none;
    transition: all 0.3s linear;
    opacity: 1;
  }
  .container {
    display: flex;
    align-items: center;
    .logo {
      width: 200px;
      height: 80px;
      background: url(../assets/images/logo.png) no-repeat right 2px;
      background-size: 160px auto;
    }
    .right-link {
      border-left: 3px solid @xtxColor;
      padding: 0 20px;
      a {
        margin: 0 20px;
        &:hover {
          color: @xtxColor;
        }
      }
    }
  }
}

</style>
